import {Component} from '@angular/core';
import {IonicModule} from '@ionic/angular';
import {Router} from '@angular/router';
import {Media, MediaObject} from '@ionic-native/media/ngx';
import {MediaCapture, MediaFile} from '@ionic-native/media-capture/ngx';

@Component({
  selector: 'play-audio',
  templateUrl: 'play-audio.page.html',
  styleUrls: ['play-audio.scss'],
  standalone: true,
  imports: [IonicModule],
})
export class PlayAudioPage {


  audio: MediaObject; // 用于存储录音对象
  constructor(private media: Media, private mediaCapture: MediaCapture) {
    this.audio = this.media.create('my_audio.mp3'); // 创建一个名为 my_audio.mp3 的录音对象
  }

  startRecording() {
    this.audio = this.media.create('my_audio.mp3'); // 创建一个名为 my_audio.mp3 的录音对象
    this.audio.startRecord(); // 开始录制
  }

  stopRecording() {
    this.audio.stopRecord(); // 停止录制
  }

  playRecording() {
    this.audio.play(); // 播放录音
  }
}
